home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7129 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.mira.net.au!news
  2. From: davidw@werple.net.au (David White)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: class self destuction???
  5. Date: 21 Feb 1996 19:48:10 +1100
  6. Organization: Werple Internet, Melbourne
  7. Message-ID: <4gem8a$4g7@werple.net.au>
  8. References: <1996Feb20.152904.13555@alw.nih.gov>
  9. NNTP-Posting-Host: werple.mira.net.au
  10.  
  11. Dean Fuqua <dfuqua@raleigh.ibm.com> writes:
  12.  
  13. >I was wondering what the *correct* method of class suicide is.
  14. >For example, while in a member function, a class realizes that 
  15. >it is no longer wanted in little computing world and that it should 
  16. >kill itself.
  17.  
  18. >Should it call it own destuctor and that's that or should it do delete(this).
  19. >The delete method seems a bit dangerous to me.
  20.  
  21. Calling its own destructor will kill it, but will not release its memory
  22. if allocated on the free store (its 'body' remains, polluting the
  23. program). But if it is a stack-allocated object, it will be killed twice,
  24. the second time possibly taking the program with it, depending on what the
  25. destructor does. So calling the destructor isn't an option in either case,
  26. except in some special situations when it can be resurrected with a
  27. placement 'new' afterwards. 'delete' should only be used if it can be
  28. guaranteed that the object was allocated with 'new'. 
  29.  
  30. David White
  31. davidw@werple.mira.net.au
  32.  
  33.